
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>data.types &#8212;  1.0.0 documentation</title>
    <link rel="stylesheet" href="../../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" src="../../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex/" />
    <link rel="search" title="Search" href="../../../search/" />
   
  <link rel="stylesheet" href="../../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for data.types</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">copy</span>


<div class="viewcode-block" id="Node"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Node">[docs]</a><span class="k">class</span> <span class="nc">Node</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Parent class for all nodes</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for Node.</span>
<span class="sd">        Initialises all needed variables</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="s1">&#39;Node&#39;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">isRoot</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">attributes</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parents</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">children</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">view</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">position</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">visited</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">finished</span> <span class="o">=</span> <span class="kc">False</span>

<div class="viewcode-block" id="Node.initDFS"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Node.initDFS">[docs]</a>    <span class="k">def</span> <span class="nf">initDFS</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialises both variables for the dfs</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">visited</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">finished</span> <span class="o">=</span> <span class="kc">False</span></div></div>


<div class="viewcode-block" id="Threat"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Threat">[docs]</a><span class="k">class</span> <span class="nc">Threat</span><span class="p">(</span><span class="n">Node</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for threat nodes</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="Countermeasure"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Countermeasure">[docs]</a><span class="k">class</span> <span class="nc">Countermeasure</span><span class="p">(</span><span class="n">Node</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for countermeasure nodes</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="Conjunction"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Conjunction">[docs]</a><span class="k">class</span> <span class="nc">Conjunction</span><span class="p">(</span><span class="n">Node</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class for conjunction nodes</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">conjunctionType</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for conjunctions.</span>
<span class="sd">        sets the conjunction type and the id, calls Node.__init__()</span>

<span class="sd">        :param id: ID of the node</span>
<span class="sd">        :param conjunctionType: Type for this conjunction</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="nb">id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">conjunctionType</span> <span class="o">=</span> <span class="n">conjunctionType</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="n">conjunctionType</span></div>


<div class="viewcode-block" id="Edge"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Edge">[docs]</a><span class="k">class</span> <span class="nc">Edge</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">     Class for edges</span>

<span class="sd">     The Class contains the source, destination and the conjunction for the edge</span>
<span class="sd">     &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">destination</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for Node.</span>
<span class="sd">        Initialises all needed variables</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">source</span> <span class="o">=</span> <span class="n">source</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">destination</span> <span class="o">=</span> <span class="n">destination</span>

    <span class="k">def</span> <span class="nf">__hash__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an hash of the edge</span>
<span class="sd">        :return: hash of the edge</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">-</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">destination</span><span class="p">)</span></div>


<div class="viewcode-block" id="Tree"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree">[docs]</a><span class="k">class</span> <span class="nc">Tree</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class which moulds the tree</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">extended</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructor for Tree</span>
<span class="sd">        This function initialises a tree with the given format</span>

<span class="sd">        :param extended: Format of the tree</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="n">extended</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">falseNodes</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cycleNode</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">meta</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;title&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;author&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;description&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;root&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        List for reserved nodeIDs while copy/paste is active</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">reservedList</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>

<div class="viewcode-block" id="Tree.getTypeRecursiveDown"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.getTypeRecursiveDown">[docs]</a>    <span class="k">def</span> <span class="nf">getTypeRecursiveDown</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the first type of a node which is not a Conjunction.</span>
<span class="sd">        The function searches downwards.</span>
<span class="sd">        If there was no other element it will return Conjunction</span>

<span class="sd">        :param node: Node to start the search from</span>
<span class="sd">        :return: Type of node</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">Conjunction</span><span class="p">):</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
            <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">node</span><span class="p">)</span></div>

<div class="viewcode-block" id="Tree.getTypeRecursiveUp"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.getTypeRecursiveUp">[docs]</a>    <span class="k">def</span> <span class="nf">getTypeRecursiveUp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the first type of a node which is not a Conjunction.</span>
<span class="sd">        The function searches upwards.</span>
<span class="sd">        If there was no other element it will return Conjunction</span>

<span class="sd">        :param node: Node to start the search from</span>
<span class="sd">        :return: Type of node</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">Conjunction</span><span class="p">):</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveUp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
            <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="n">node</span><span class="p">)</span></div>

<div class="viewcode-block" id="Tree.getFirstElementRecursiveDown"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.getFirstElementRecursiveDown">[docs]</a>    <span class="k">def</span> <span class="nf">getFirstElementRecursiveDown</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the first node which is not a Conjunction.</span>
<span class="sd">        The function searches downwards.</span>
<span class="sd">        If there was no other element it will return the Conjunction</span>

<span class="sd">        :param node: Node to start the search from</span>
<span class="sd">        :return: node</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">Conjunction</span><span class="p">):</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">getFirstElementRecursiveDown</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">node</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">node</span></div>

<div class="viewcode-block" id="Tree.getFirstElementRecursiveUp"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.getFirstElementRecursiveUp">[docs]</a>    <span class="k">def</span> <span class="nf">getFirstElementRecursiveUp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the first node which is not a Conjunction.</span>
<span class="sd">        The function searches upwards.</span>
<span class="sd">        If there was no other element it will return the Conjunction</span>

<span class="sd">        :param node: Node to start the search from</span>
<span class="sd">        :return: node</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">):</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">],</span> <span class="n">Conjunction</span><span class="p">):</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">getFirstElementRecursiveUp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">]</span>
            <span class="k">return</span> <span class="n">node</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">node</span></div>

<div class="viewcode-block" id="Tree.addNode"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.addNode">[docs]</a>    <span class="k">def</span> <span class="nf">addNode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a node to the tree</span>

<span class="sd">        :param node: node to add to the tree</span>
<span class="sd">        :return: True if succeed else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">node</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getNextID</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">id</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="s1">&#39;No free node IDs left&#39;</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">id</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">lastError</span> <span class="o">=</span> <span class="s1">&#39;Node ID already in tree&#39;</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">]</span> <span class="o">=</span> <span class="n">node</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.addEdge"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.addEdge">[docs]</a>    <span class="k">def</span> <span class="nf">addEdge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sourceId</span><span class="p">,</span> <span class="n">destinationId</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds a edge to the tree</span>

<span class="sd">        :param sourceId: Id of the source node</span>
<span class="sd">        :param destinationId: Id of the destination node</span>
<span class="sd">        :return: True if add was successful else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">sourceId</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="n">destinationId</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="n">source</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">sourceId</span><span class="p">]</span>
        <span class="n">destination</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">destinationId</span><span class="p">]</span>

        <span class="n">edge</span> <span class="o">=</span> <span class="n">Edge</span><span class="p">(</span><span class="n">sourceId</span><span class="p">,</span> <span class="n">destinationId</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">edge</span><span class="o">.</span><span class="fm">__hash__</span><span class="p">()</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="fm">__hash__</span><span class="p">():</span>
                <span class="k">return</span> <span class="kc">False</span>

        <span class="k">if</span> <span class="n">destinationId</span> <span class="o">==</span> <span class="n">sourceId</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveUp</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Countermeasure</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Threat</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">destination</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">Conjunction</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">Conjunction</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">children</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Threat</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Threat</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">children</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Countermeasure</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Countermeasure</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">children</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Countermeasure</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">destination</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">):</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveUp</span><span class="p">(</span><span class="n">source</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">Conjunction</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="n">Conjunction</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">getFirstElementRecursiveUp</span><span class="p">(</span><span class="n">source</span><span class="p">)</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">Conjunction</span> \
                        <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">])</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">getTypeRecursiveDown</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
                    <span class="k">return</span> <span class="kc">False</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">edge</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">edge</span><span class="o">.</span><span class="n">source</span><span class="p">]</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">edge</span><span class="o">.</span><span class="n">destination</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">edge</span><span class="o">.</span><span class="n">destination</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">edge</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.checkMeta"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.checkMeta">[docs]</a>    <span class="k">def</span> <span class="nf">checkMeta</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if the needed meta information are there</span>

<span class="sd">        :return: True if meta information are correct else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="s1">&#39;author&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span><span class="p">[</span><span class="s1">&#39;author&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span> \
                <span class="ow">or</span> <span class="s1">&#39;title&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">meta</span><span class="p">[</span><span class="s1">&#39;title&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.checkNodes"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.checkNodes">[docs]</a>    <span class="k">def</span> <span class="nf">checkNodes</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if all nodes have needed parameters and saves them into falseNodes</span>

<span class="sd">        :return: False if len(falseNodes) &gt; 0 else True</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">falseNodes</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">v</span><span class="o">.</span><span class="n">title</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">falseNodes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">False</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">falseNodes</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.checkExtended"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.checkExtended">[docs]</a>    <span class="k">def</span> <span class="nf">checkExtended</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if the Tree is an extended or an simple tree</span>

<span class="sd">        :return: True if tree is extended else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Conjunction</span><span class="p">)</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">children</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">return</span> <span class="kc">True</span>
            <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">isRoot</span> <span class="ow">is</span> <span class="kc">False</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">return</span> <span class="kc">True</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="kc">True</span>
                <span class="k">return</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extended</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Tree.checkCycle"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.checkCycle">[docs]</a>    <span class="k">def</span> <span class="nf">checkCycle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Checks if the tree has a cycle with the dfs</span>
<span class="sd">        :return: True if the tree has no cycle else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">n</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">n</span><span class="o">.</span><span class="n">initDFS</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">n</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfs</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.dfs"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.dfs">[docs]</a>    <span class="k">def</span> <span class="nf">dfs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Depth-first search to check the tree for a cycle</span>

<span class="sd">        :param node: Node to check</span>
<span class="sd">        :return: True if node is finished false if a cycle is detected</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">finished</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">if</span> <span class="n">node</span><span class="o">.</span><span class="n">visited</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">cycleNode</span> <span class="o">=</span> <span class="n">node</span>
            <span class="k">return</span> <span class="kc">False</span>
        <span class="n">node</span><span class="o">.</span><span class="n">visited</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">for</span> <span class="n">subN</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dfs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">subN</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">c</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">return</span> <span class="kc">False</span>
        <span class="n">node</span><span class="o">.</span><span class="n">finished</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="kc">True</span></div>

<div class="viewcode-block" id="Tree.getNextID"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.getNextID">[docs]</a>    <span class="k">def</span> <span class="nf">getNextID</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keyList</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the next free id for a node in the format N[0-9]{4}</span>

<span class="sd">        :param: keyList list of keys already used</span>
<span class="sd">        :return: next free node id</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">keyList</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">keyList</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10000</span><span class="p">):</span>
            <span class="k">if</span> <span class="s1">&#39;N&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">zfill</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span> <span class="ow">and</span> <span class="s1">&#39;N&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">zfill</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">keyList</span> \
                    <span class="ow">and</span> <span class="s1">&#39;N&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">zfill</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">reservedList</span><span class="p">:</span>
                <span class="k">return</span> <span class="s1">&#39;N&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">zfill</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">None</span></div>

<div class="viewcode-block" id="Tree.removeNode"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.removeNode">[docs]</a>    <span class="k">def</span> <span class="nf">removeNode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nodeId</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Removes a node and all edges to an from this node</span>
<span class="sd">        :param nodeId: Id of the node which need to deleted</span>
<span class="sd">        :return: True if it was successful else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">nodeId</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">:</span>
            <span class="n">parents</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">nodeId</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">parents</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">removeEdge</span><span class="p">(</span><span class="n">i</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="n">nodeId</span><span class="p">)</span>
            <span class="n">children</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">nodeId</span><span class="p">]</span><span class="o">.</span><span class="n">children</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">children</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">removeEdge</span><span class="p">(</span><span class="n">nodeId</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="n">i</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">nodeId</span><span class="p">]</span><span class="o">.</span><span class="n">isRoot</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">nodeId</span><span class="p">]</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Tree.removeEdge"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.removeEdge">[docs]</a>    <span class="k">def</span> <span class="nf">removeEdge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">edgeId</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Removes an edge</span>

<span class="sd">        :param edgeId: Id of the edge (hash)</span>
<span class="sd">        :return: True if successful else false</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">edge</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">edgeId</span> <span class="o">==</span> <span class="n">e</span><span class="o">.</span><span class="fm">__hash__</span><span class="p">():</span>
                <span class="n">edge</span> <span class="o">=</span> <span class="n">e</span>
                <span class="k">break</span>
        <span class="k">if</span> <span class="n">edge</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">edge</span><span class="o">.</span><span class="n">source</span><span class="p">]</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">edge</span><span class="o">.</span><span class="n">destination</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">edge</span><span class="o">.</span><span class="n">destination</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">edge</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">edge</span><span class="p">)</span>
            <span class="k">return</span> <span class="kc">True</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">False</span></div>

<div class="viewcode-block" id="Tree.makeSimple"><a class="viewcode-back" href="../../../attackTreeDraw.data/#data.types.Tree.makeSimple">[docs]</a>    <span class="k">def</span> <span class="nf">makeSimple</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Generates an simple tree out of an extended one.</span>

<span class="sd">        Copies every element with two or more parents.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">nodeList</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">)</span>
        <span class="n">changed</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="k">for</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">nodeList</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">newNode</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
                <span class="n">newNode</span><span class="o">.</span><span class="n">id</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="n">newNode</span><span class="o">.</span><span class="n">parents</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">newNode</span><span class="o">.</span><span class="n">children</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">addNode</span><span class="p">(</span><span class="n">newNode</span><span class="p">)</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">removeEdge</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">parents</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="n">node</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">addEdge</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">newNode</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
                <span class="n">newNode</span><span class="o">.</span><span class="n">children</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">children</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">newNode</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">edgeList</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">Edge</span><span class="p">(</span><span class="n">newNode</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">c</span><span class="p">))</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">nodeList</span><span class="p">[</span><span class="n">c</span><span class="p">]</span><span class="o">.</span><span class="n">parents</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">newNode</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
                <span class="n">changed</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">if</span> <span class="n">changed</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">makeSimple</span><span class="p">()</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../../">Documentation overview</a><ul>
  <li><a href="../../">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../../search/" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2018, Daniel Fischer.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.10</a>
      
    </div>

    

    
  </body>
</html>